%% @author Rain
%% @doc 游戏应用


-module(game).
-behaviour(application).
-export([start/2, stop/1,
		 start/0]).

-include("net.hrl").

%% ====================================================================
%% API functions
%% ====================================================================
-export([test/0]).



%% ====================================================================
%% Behavioural functions
%% ====================================================================

%% start/2
%% ====================================================================
%% @doc <a href="http://www.erlang.org/doc/apps/kernel/application.html#Module:start-2">application:start/2</a>
-spec start(Type :: normal | {takeover, Node} | {failover, Node}, Args :: term()) ->
	{ok, Pid :: pid()}
	| {ok, Pid :: pid(), State :: term()}
	| {error, Reason :: term()}.
%% ====================================================================
start() ->
	start(normal, []).
start(_, _) ->
	util:reload_all_ebin(),
	case net_acceptor_svr:start_link(?SERVER_PORT) of
		{ok, Pid} ->
			init_server(),
			io:format("===================GAME SERVER START SUCCESS ==================~n"),
			{ok, Pid};
		Error ->
			io:format("===================GAME SERVER START FAIL ==================~n"),
			io:format("Reason:  ~p~n", [Error]),
			Error
	end.

test() ->
	io:format("Hello World~n").

init_server() ->
	global_svr:start_link(),
	ets_svr:start_link().

%% stop/1
%% ====================================================================
%% @doc <a href="http://www.erlang.org/doc/apps/kernel/application.html#Module:stop-1">application:stop/1</a>
-spec stop(State :: term()) ->  Any :: term().
%% ====================================================================
stop(State) ->
    ok.

%% ====================================================================
%% Internal functions
%% ====================================================================


